package com.myccb.app.view.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.myccb.app.R;
import com.myccb.app.view.index.LoanActivity;
import com.myccb.app.view.index.Loannull;
import com.myccb.app.view.investment.My_life;
import com.myccb.app.view.investment.PromotionActivity_investment;
import com.myccb.app.widget.rollpageview.ColorPointHintView;
import com.myccb.app.widget.rollpageview.LoopPagerAdapter;
import com.myccb.app.widget.rollpageview.RollPagerView;

/**
 * Created by hyt on 2017/11/24.
 */

public class LifeFragment extends Fragment {

    private static LifeFragment instance;

    public static LifeFragment getInstance(){
        if (instance==null)
            instance=new LifeFragment();
        return instance;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_life, null);
        initView(view);
        return view;
    }
    private TextView My_Life;
    private void initView(View view){


        My_Life=view.findViewById(R.id.My_Life);
        My_Life.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(),My_life.class);
                startActivity(intent);
            }
        });

        (view.findViewById(R.id.life_mainpage_promotion)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getActivity(), PromotionActivity_investment.class);
                startActivity(intent);
            }
        });

        RollPagerView lifeAdv=view.findViewById(R.id.life_mainpage_ads);
        lifeAdv.setHintView(new ColorPointHintView(getContext(),getResources().getColor(R.color.colorPrimary),getResources().getColor(R.color.Grey200)));
        lifeAdv.setAdapter(new LoopPagerAdapter(lifeAdv) {
            private int[] adImgs={
                    R.mipmap.index_main_home_adv_1, R.mipmap.index_main_home_adv_2,
                    R.mipmap.index_main_home_adv_3, R.mipmap.index_main_home_adv_4
            };
            @Override
            public View getView(ViewGroup container, int position) {
                ImageView view = new ImageView(container.getContext());
                view.setImageResource(adImgs[position]);
                view.setScaleType(ImageView.ScaleType.CENTER_CROP);
                view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
                return view;
            }
            @Override
            public int getRealCount() {
                return adImgs.length;
            }
        });
    }

}
